package m1;

import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;

import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class Producer {
    public static void main(String[] args) throws MQClientException, RemotingException, InterruptedException, MQBrokerException {
        //创建生产者
        DefaultMQProducer p = new DefaultMQProducer("producer-group1");
        //设置注册中心的地址rocketmq
        p.setNamesrvAddr("192.168.64.141:9876");
        //启动生产者(建立连接)
        p.start();

        while (true){
            System.out.println("输入消息");
            String s = new Scanner(System.in).nextLine();
            //创建消息对象 封装
            //Topic相当于
            Message message = new Message("Topic1", "TagA",s.getBytes(StandardCharsets.UTF_8));
            message.setDelayTimeLevel(3);
            //发送消息
            SendResult r = p.send(message);
            System.out.println(r);
        }
    }
}